<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017\10\16 0016
 * Time: 9:53
 */
namespace Home\Controller;
use Think\Controller;

class LoginController extends Controller{
    public function index(){
        if(!IS_POST){
            $this->display();
        }else{
            $post=I("post.");
            $account=$post["account"];
            $password=sha1($post["password"]);
            $login=M("user")->where("account='{$account}' and password='{$password}'")->select();
            if($login){
                $_SESSION["uid"]=$login[0]['id'];
                $this->success("登录成功","/index/index");
            }else{
                $this->error("账号或密码不对","/login/index");
            }
        }
    }
    public function logout(){
        $_SESSION['uid']="";
        $this->redirect("/login/index",[],'',"123");
    }
    //验证码
    public function yzm(){
        $str ='0123456789';
        $verify = new \Think\Verify(['imageH' =>40,'imageW'=>110, 'fontSize'=>15,'length'=>4,'useCurve'  =>false, 'expire'=> 1800]);
        $verify->entry($_GET['id']);
    }
    //验证码ajax检测
    public function check(){
        $verify = new \Think\Verify();
        $bool = $verify->check($_GET['yzm'],$_GET['id']);
        if($bool){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function _empty(){
        $this->display("没有这个方法");
    }
}